from flask_wtf import FlaskForm
from wtforms import IntegerField,StringField,FloatField,PasswordField,SubmitField,validators
from wtforms.validators import Length,InputRequired,Email
from models import Money


class stealForm(FlaskForm):
    password=PasswordField("密码:",validators=[Length(6,20),InputRequired()])
    email=StringField("电子邮件:",validators=[Email()])
    username=StringField("用户名:",validators=[InputRequired()])
    total=FloatField("金额:",validators=[InputRequired()])
    submit=SubmitField('提交')

class registerForm(FlaskForm):
    email=StringField("电子邮件:",validators=[Email()])
    password=PasswordField('密码:',validators=[InputRequired(),Length(6,20)])

    def validate(self):
        result=super(registerForm,self).validate()
        if not result:
            print('你的登录的格式不通过')
            return False
        user=Money.query.filter(Money.email==self.email.data,Money.password==self.password.data).first()
        if user:
            return True
        else:
            self.email.errors.append('你的邮箱或者密码错误！')
            return False

class TransferForm(FlaskForm):
    email=StringField(validators=[Email()])
    money=FloatField(validators=[InputRequired()])

    def validate(self):
        result=super(TransferForm,self).validate()
        if not result:
            print('你的输入的转账格式不正确!')
            return False
        user=Money.query.filter(Money.email==self.email.data).first()
        if user:
            return True
        else:
            self.email.errors.append('你的邮箱或者密码错误!')
            return False
